<!DOCTYPE html>

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <script src="./js/vue.js"></script>
    <script src="./js/vue-router.js"></script>
    <style>
        #app {
            display: flex;
            background-color: aliceblue;
        }

        .nav {
            border: 5px solid aqua;
            width: 200px;
            height: 800px;
            margin: 10px;
            text-align: center;
            font-size: 30px;

        }

        .content {
            border: 5px solid lawngreen;
            width: 100%;
            height: 800px;
            margin: 10px;
        }
    </style>

</head>

<body>
    <div id="app">
        <div class="nav">
            <router-link to="/teacher">教师管理</router-link><br>
            <router-link to="/student">学生管理</router-link><br>
            <router-link to="/abc">后勤管理</router-link>


        </div>
        <div class="content">
            <router-view></router-view>
        </div>
    </div>
    <script>
        //1*定义组件
        var comA = {
            template: `
            <div>教师管理</div>
            `,
        }
        var comB = {
            template: `
            <div>
                学生管理
                <div>
                    <button @click="clickHander">成绩管理</button>
                    <button @click="clickHander">学籍管理</button>              
                </div>
                <div>
                <router-view></router-view>
                </div>
            </div>
            `,
            methods: {
                clickHander(e) {
                    if(e.target.innerText == '成绩管理') {
                        this.$router.push({
                            path:'/student/grade',
                        query:{name:'zhangsan',age:20}
                        })
                    }else{
                        this.$router.push({
                            // path:'/student/xueji',
                            name:'reg',
                            params:{
                                name:'lisi',
                                gender:'male'
                            }
                        })
                    }

                }
            }
        }
        var comC = {
            template: `
            <div>后勤管理</div>
            `,
        }
        var grade = {
            template: `
            <div>学生成绩管理</div>
            `,
        }
        var xueji= {
            template: `
            <div>学生学籍管理
                <button @click="back">返回</button>
             </div>
            `,
            methods:{
                back(){
                    this.$router.go(-1)
                }
            }
        }
        //2*定义路由
        var router = new VueRouter({
            mode: 'history',
            routes: [
                {
                    path: '/teacher',
                    component: comA
                },
                {
                    path: '/student',
                    component: comB,
                    children: [
                        {
                            path: 'grade',
                            component: grade
                        },
                        {
                            path: 'xueji',
                            component: xueji,
                            name:'reg'
                        }

                    ]
                },
                {
                    path: '/abc',
                    component: comC
                },
            ]
        })

        var vm = new Vue({
            el: '#app',
            data: {},
            methods: {},
            //3*注册路由
            router

        })
    </script>
</body>

</html>